package org.dong.base.thread.deadlock;

public class Count {
    private final byte[] lock1 = new byte[1];
    private final byte[] lock2 = new byte[1];

    private int num = 0;

    public void add() {
        synchronized (lock1) {
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            synchronized (lock2) {
                num++;
            }
            System.out.println(Thread.currentThread().getName() + "-" + num);
        }
    }

    public void lockMethod(){
        synchronized (lock2){
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            synchronized (lock1){
                num++ ;
            }
        }
    }
}
